﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//用携程写动画效果
public delegate void FunBack();
public class UITween : MonoBehaviour
{
    Vector2 startPos;
    Vector2 targetPos;
    public Vector2 offsetPos;
    FunBack funBack;

    private void Awake()
    {
        startPos = transform.position;
    }
    public IEnumerator MoveTo()
    {
        Vector2 target2 = targetPos;
        RectTransform rect = GetComponent<RectTransform>();
        while (Mathf.Abs(rect.position.x - target2.x) > 10)
        {
            rect.position = Vector2.Lerp(rect.position, target2, 1f);
            yield return new WaitForFixedUpdate();
        }
        if (funBack != null)
        {
            funBack();
            funBack = null;
        }
        FunIE();
    }

    public void FunIE()
    {
        StopCoroutine(MoveTo());
    }
    public void SetButtonHandle(FunBack fun)
    {
        funBack = fun;
    }
    public void setTargetPos()
    {
        targetPos = offsetPos + new Vector2(Screen.width / 2, Screen.height / 2);
    }
    public void SetStartPos()
    {
        targetPos = startPos;
    }
}